//@version: $Id: UserInput.h 140 2010-12-09 00:17:53Z beermanforlife $
#pragma once
#define NUMBEROFSHAPESPERROWORCOL 6

//Struct used to move data regarding grid and screen coordinates around
struct Location
{
	int x, y;

	inline bool operator!=(Location& loc)
	{
		return (this->x != loc.x) || (this->y != loc.y);
	}
};

class UserInput
{
private:
	int mScreenXSize, mScreenYSize;
	//mouse location represented in grid coordeinates
	Location mouseGridLocation;
	//mouse location represented in screen coordinates
	Location mouseScreenLocation;
	bool clicked;
	bool pressed;

	//variable that will store the last key pressed
	char keyThatWasPressed;
public:
	//constructor
	UserInput()
	{
		//things to init
		clicked = false;
		pressed = false;
	}

	//Simply gets the size of the screen
	//Under current conditions the map is to be the full size of the window
	void GetScreenSize(int aX, int aY)
	{
		mScreenXSize = aX;
		mScreenYSize = aY;
	}

	//these are to set and unset the click bool
	void pressButton(){clicked = true;}
	void releasedButton(){clicked = false;}
	bool isThereAClick(){return clicked;}

	//used to toggle the state of a key being pressed on the keyboard
	void pressKey(){pressed = true;}
	void releaseKey(){pressed = false;}
	bool isThereAKey(){return pressed;}

	//This takes an x and y location then converts it to a grid location and sets it in the location.
	void ConvertScreenToGrid(int aX, int aY)
	{
		//just incase we need the actual screen location we are saving it
		mouseScreenLocation.x = aX;
		mouseScreenLocation.y = aY;
		//temp ints to find grid size based on window size
		int gridXSize, gridYSize;
		gridXSize = gridYSize = 0;

		//finds the size per grid square
		gridXSize = mScreenXSize / NUMBEROFSHAPESPERROWORCOL;
		gridYSize = mScreenYSize / NUMBEROFSHAPESPERROWORCOL;

		//does the convert to grid space and sets it in mouseLocation
		if(gridXSize != 0 && gridYSize!=0){
			mouseGridLocation.x = aX / gridXSize;
			mouseGridLocation.y = aY / gridYSize;
		}
		if(mouseGridLocation.x >= 6){mouseGridLocation.x = 5;}
		if(mouseGridLocation.y >= 6){mouseGridLocation.y = 5;}
	}

	//returns the locaiton of the mouse's last position.
	Location getLocationOfMouse() {return mouseGridLocation;}

	//keeps track of the mouses movement on the screen
	void trackMouse(int aX, int aY)
	{
		//Needs to be filled in
		//currently returns nothing and takes no variables
		ConvertScreenToGrid(aX, aY);
	}

	//returns the location of the last mouse click
	Location mouseClick()
	{
		//temp value for unit test
		//uses trackMouse()
		//uses convertScreenToGrid()
		return mouseGridLocation;
	}

	//saves the last key pressed on the keyboard
	void storeKeyPress(char tempChar)
	{
		//this will watch for any presses of the kayboard
		//once one is pressed it will return the char pressed
		keyThatWasPressed = tempChar;
	}

	char getKeyThatWasPressed(){return keyThatWasPressed;}

};